<template>
  <div>
    <el-tooltip placement="left" :content="isView ? '详情' : '修改'">
      <el-button size="mini" type="primary" :icon="isView ? 'el-icon-more' : 'el-icon-edit'" @click="linkTo" />
    </el-tooltip>
    <eForm ref="form" :sup-this="supThis" :is-add="false" :is-view="isView" />
  </div>
</template>
<script>
import eForm from './form'
// import { queryEngineerMoney } from '@/api/tEngineerMoney';
import { getEqptType } from '@/api/tEqpttype';
// import { TextToCode } from 'element-china-area-data';
export default {
  components: { eForm },
  props: {
    isView: {
      type: Boolean,
      required: true
    },
    data: {
      type: Object,
      required: true
    },
    supThis: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      contractMoney: {
        tableList: []
      },
      eqptsystem: ''
    }
  },
  mounted: function() {
    console.log(this.data);
  },
  methods: {
    linkTo() {
      this.to()
      /*
      const target = this;
      queryEngineerMoney(target.data.id, target.data.contractCode).then((tableList) => {
        console.log(target['data']);
        this.contractMoney = {
          tableList
        };
        this.to();
      }); */
    },
    to() {
      const _this = this.$refs.form
      const target = this
      console.log(this.data.contractMoney === true);
      const contractMoney = {
        tableList: this.data.engineerMoney && JSON.parse(this.data.engineerMoney) || options
      };
      /* const { serveProvinces, serveCity, serveCounty } = this.data;*/
      _this.getEqptBrand()
      _this.getEqptSystem()
      getEqptType(this.data.deviceType).then((res) => {
        this.eqptsystem = res.content[0].eqptsystemid
        _this.selectFun(res.content[0].eqptsystemid)
        _this.form = {
          id: this.data.id,
          contractCode: this.data.contractCode,
          contractName: this.data.contractName,
          attachments: this.data.attachments,
          contractContent: this.data.contractContent,
          contractItemId: this.data.contractItemId,
          contractItemName: this.data.contractItemName,
          customerId: this.data.customerId,
          customerName: this.data.customerName,
          startTime: this.data.startTime,
          endTime: this.data.endTime,
          creatTime: this.data.creatTime,
          serveMoney: this.data.serveMoney,
          eqptsystem: this.eqptsystem,
          deviceFactory: this.data.deviceFactory && parseInt(this.data.deviceFactory),
          deviceType: this.data.deviceType && parseInt(this.data.deviceType),
          deviceModel: this.data.deviceModel && parseInt(this.data.deviceModel),
          partsDescription: this.data.partsDescription,
          serveCountry: this.data.serveCountry,
          serveProvinces: this.data.serveProvinces,
          serveCity: this.data.serveCity,
          serveCounty: this.data.serveCounty,
          serveAddress: this.data.serveAddress,
          serveTime: this.data.serveTime,
          deviceCondition: this.data.deviceCondition,
          country: this.data.serveCountry,
          province: this.data.serveProvinces,
          city: this.data.serveCity,
          county: this.data.serveCounty,
          engineerMoney: this.data.engineerMoney || JSON.stringify(options)
        }
        _this.contractMoney = JSON.parse(JSON.stringify(contractMoney));
        _this.selectBrand(target.data.deviceFactory)
        _this.files = []
        this.data.attachments.split(',').forEach(function(data, index) {
          if (data !== null && data !== '') {
            _this.files.push({ name: data, id: data, url: '/api/picture/' + data })
          }
        })
        /* if (serveProvinces && serveCity && serveCounty) {
          _this.region = [TextToCode[serveProvinces].code, TextToCode[serveProvinces][serveCity].code, TextToCode[serveProvinces][serveCity][serveCounty].code]
        }*/
        _this.dialog = true
      })
    }
  }
}
const options = [
  {
    engineerType: '网络',
    engineerLevel: '初级',
    engineerCost: ''
  },
  {
    engineerType: '网络',
    engineerLevel: '中级',
    engineerCost: ''
  },
  {
    engineerType: '网络',
    engineerLevel: '高级',
    engineerCost: ''
  },
  {
    engineerType: '系统',
    engineerLevel: '初级',
    engineerCost: ''
  },
  {
    engineerType: '系统',
    engineerLevel: '中级',
    engineerCost: ''
  },
  {
    engineerType: '系统',
    engineerLevel: '高级',
    engineerCost: ''
  },
  {
    engineerType: '弱电',
    engineerLevel: '初级',
    engineerCost: ''
  },
  {
    engineerType: '弱电',
    engineerLevel: '中级',
    engineerCost: ''
  },
  {
    engineerType: '弱电',
    engineerLevel: '高级',
    engineerCost: ''
  }
]
</script>

<style scoped>
  div{
    display: inline-block;
    margin-right: 3px;
  }
</style>
